#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using VisualDB.DAL;

#endregion

namespace VisualDB
{
    public partial class PreviewQueryForm : Form
    {
        private IDatabaseDAL _databaseDAL;

        public PreviewQueryForm(IDatabaseDAL databaseDAL, string query)
        {
            InitializeComponent();

            this.txtQuery.Text = query;
            _databaseDAL = databaseDAL;
        }

        public string Query
        {
            get
            {
                return this.txtQuery.Text;
            }
        }

        public IDatabaseDAL DatabaseDAL
        {
            get
            {
                return _databaseDAL;
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string errors;

            int retVal = _databaseDAL.ExecuteCommand(this.Query, out errors);

            if (errors == "")
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                this.txtErrors.Text = errors;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}